package com.xkstream.client.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xkstream.client.R;
import com.xkstream.client.entity.BetRank;
import com.xkstream.client.utils.AsyncImage;

import java.util.List;

/**
 * Created by admin on 2017/3/28.
 */

public class BetonRankAdapter extends BaseAdapter{
    private Context context ;
    private List<BetRank> list ;

    public BetonRankAdapter(Context context,List<BetRank> list){
        this.context = context;
        this.list = list ;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.layout_betonrank_item,null);
            holder.ivHeader = (ImageView)convertView.findViewById(R.id.ivHeader);
            holder.tvName = (TextView)convertView.findViewById(R.id.tvName);
            holder.ivRank = (ImageView)convertView.findViewById(R.id.ivRank);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        BetRank betRank = list.get(position);
        holder.tvName.setText(betRank.getNickname());
        AsyncImage.loadPhoto(context,betRank.getIcon(),holder.ivHeader);
        if(position == 0){
            holder.ivRank.setImageDrawable(context.getResources().getDrawable(R.drawable.beton_one));
        }else if(position == 1){
            holder.ivRank.setImageDrawable(context.getResources().getDrawable(R.drawable.beton_two));
        }else if(position == 2){
            holder.ivRank.setImageDrawable(context.getResources().getDrawable(R.drawable.beton_three));
        }
        return convertView;
    }

    private class ViewHolder{
        ImageView ivHeader;
        TextView tvName;
        ImageView ivRank;
    }
}
